<?php

use yii\db\Migration;

class m000003_000002_create_user_log extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%user_log}}', [
            'id' => $this->primaryKey(),
            'uid' => $this->integer()->notNull()->comment('用户编号'),
            'time' => $this->integer()->notNull()->comment('时间'),
            'info' => $this->string(128)->notNull()->comment('信息'),
            'data' => $this->text()->comment('数据'),
        ]);
        $this->createIndex('fk_user_log_user1_idx', '{{%user_log}}', ['uid']);
        try {
            $this->addForeignKey('fk_user_log_user1', '{{%user_log}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
    }

    public function down()
    {
        $this->dropTable('{{%user_log}}');
    }
}
